How do I output an individual character when using char *[] = "something"

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-04-29T06:22:24Z Indexed on 2010/04/29 6:27 UTC
Read the original article Hit count: 233

Filed under:
|
|

I've been playing with pointers to better understand them and I came across something I think I should be able to do, but can't sort out how. The code below works fine - I can output "a", "dog", "socks", and "pants" - but what if I wanted to just output the 'o' from "socks"? How would I do that?

char *mars[4] = { "a", "dog", "sock", "pants" };

for ( int counter = 0; counter < 4; counter++ )
{
  cout << mars[ counter ];
}

Please forgive me if the question is answered somewhere - there are 30+ pages of C++ pointer related question, and I spent about 90 minutes looking through them, as well as reading various (very informative) articles, before deciding to ask.

© Stack Overflow or respective owner

Related posts about c++

Related posts about pointer